package com.boolib.fdfs;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.Getter;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
public class ServerResponse<T> {


    private int status;

    private String message;


    private  T data;


    private ServerResponse(int status){
        this.status = status;
    }


    private ServerResponse(int status,String message){
        this.status = status;
        this.message = message;
    }

    private ServerResponse(int status,String message,T data){
        this.status = status;
        this.message = message;
        this.data = data;
    }


    private ServerResponse(int status,T data){
        this.status = status;
        this.data = data;
    }


    @JsonIgnore
    public boolean isSuccess(){
        return this.status  == ResponseCode.SUCCESS.getCode();
    }

    public static <T> ServerResponse<T> createBySuccess(){
            return  new ServerResponse<>(ResponseCode.SUCCESS.getCode());
    }

    public static <T> ServerResponse<T> createBySuccess(T data){
        return  new ServerResponse<>(ResponseCode.SUCCESS.getCode(),data);
    }

    public static <T> ServerResponse<T> createBySuccess(String message,T data){
        return  new ServerResponse<>(ResponseCode.SUCCESS.getCode(),message,data);
    }

    public static <T> ServerResponse<T> createBySuccessMessage(String message){
        return  new ServerResponse<>(ResponseCode.SUCCESS.getCode(),message);
    }


    public static <T> ServerResponse<T> createByError(){
        return  new ServerResponse<>(ResponseCode.Error.getCode());
    }


    public static <T>  ServerResponse<T> createByError(int code,String message){
        return  new ServerResponse<>(code,message);
    }

    public static <T>  ServerResponse<T> createByErrorMessage(String message){
        return  new ServerResponse<>(ResponseCode.Error.getCode(),message);
    }




















}
